<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "{{%url_task}}".
 *
 * @property integer $id
 * @property string $file_name
 * @property string $suffix
 * @property integer $cnt
 * @property string $analyze_type
 * @property integer $analyze_cnt
 * @property string $create_time
 */
class Task extends \yii\db\ActiveRecord
{

    const TYPE_LIANTONG =   1;
    const TYPE_JS   =   2;
    const TYPE_PE   =   3;
    const TYPE_ELF  =   4;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%url_task}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['cnt', 'analyze_cnt'], 'integer'],
            [['create_time'], 'safe'],
            [['file_name'], 'string', 'max' => 255],
            [['suffix', 'analyze_type'], 'string', 'max' => 50]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'file_name' => '文件名',
            'suffix' => '文件后缀',
            'cnt' => '数据条数',
            'analyze_type' => '需要解析类型',
            'analyze_cnt' => '已解析数量',
            'create_time' => '上传时间',
        ];
    }

    public static function getAnalyzeType($status = null){
        $status_arr= [
            self::TYPE_LIANTONG=>'检测通联指令',
            self::TYPE_JS=>'检测js代码',
            self::TYPE_PE=>'检测PE文件',
            self::TYPE_ELF=>'检测ELF文件',
        ];
        if(!is_null($status)){
            $status = explode(',',$status);
            $str = '';
            foreach ($status as $statu) {
                $str.=  isset($status_arr[$statu])?$status_arr[$statu]:'';
                $str.= ",";
            }
            return $str;
        }
        return $status_arr;
    }
}
